<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class GuanlixiaoquController extends AdminbaseController{
    
    
    protected $menu_model;
    protected $model_building;
    protected $model_house;


    function _initialize() {
        parent::_initialize();
        $this->menu_model = M("xiaoqu");
        $this->model_building=M("building");
         $this->model_house=M("house");

    }
	
    
	public function add(){
		
            $this->assign('id', get_current_admin_id());
            $this->display();
		
		
	}
	
	public function xiaoqulist(){
		
            $info=$this->menu_model->select();
            
            $this->assign('info', $info);
		
		$this->display();
		
	}
	
	public function louyuguanli(){
            
           $lylist= $this->model_building->select();
           
           $this->assign('lylist',$lylist);
		
		$this->display();
		
	}
	
	public function fangwu(){
            
             $fwlist= $this->model_house->select();
           
           $this->assign('fwlist',$fwlist);
		
		$this->display();
		
		
	}
        
         public function add_post() {
    	if (IS_POST) {
    		if ($this->menu_model->create()) {
    			if ($this->menu_model->add()!==false) {
                         
                               $this->menu_model->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");
    			}
    		} else {
    			$this->error($this->menu_model->getError());
    		}
               
    	}
    }
    
    
    function delete(){
        $id = intval(I("get.id")); 
          $count = $this->menu_model->where(array("parentid" => $id))->count();
    
        if ($this->menu_model->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
        
        
    }
    
    function updata(){
 
        $id = intval(I("get.id"));
        $res=$this->menu_model->where('id=%d',array($id))->select();
       $this->assign('res', $res);
        $this->display(); 
        
        
    }
    function save(){

       	if (IS_POST) {
    		if ($this->menu_model->create()) {
    			if ($this->menu_model->save()!==false) {
                            $uid=get_current_admin_id();
                           
                               $this->menu_model->where('id=%d',array($_POST['id']))->save();
    				 $this->success("更新成功！");
    			} else {
    				$this->error("更新失败！");
    			}
    		} else {
    			$this->error($this->menu_model->getError());
    		}
               
    	}
        
    }
      
    function ly_add(){
        $uid=get_current_admin_id();
       $xqs= $this->menu_model->where('uid=%d',$uid)->select();
        
       $this->assign('xqs',$xqs);
        
        $this->display();
    }
       
    function lyadd_post(){
        if(IS_POST){
            if($this->model_building->create()){
                if($this->model_building->add()!=false){
                   
                               $this->model_building->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");   
                    
                    
                }
                
            }
            
            
            
        }
     
        
    }
    
    function fw_add(){
         $xqs= $this->menu_model->select();
       
        
       $this->assign('xqs',$xqs);
        
        $this->display();
    }
    
    function fwadd_change(){
          $lys=$this->model_building->where("areaid=%d",$_POST['id'])->select();
         $php_json = json_encode($lys); 

        echo $php_json;
    }
     function dy_change(){
          $lys=$this->model_building->where("areaid=%d",$_POST['id'])->select();
         $php_json = json_encode($lys); 

        echo $php_json;
    }
    function fwadd_post(){
          if(IS_POST){
            if($this->model_house->create()){
                if($this->model_house->add()!=false){
                   
                               $this->model_house->add();
    				 $this->success("添加成功！");
    			} else {
    				$this->error("添加失败！");   
                    
                    
                }
                
            }
            
            
            
        }
    }
    function lydelete(){
          $id = intval(I("get.id")); 
          $count = $this->model_building->where(array("parentid" => $id))->count();
    
        if ($this->model_building->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
     
    }
    function  fwdelete(){
         $id = intval(I("get.id")); 
          $count = $this->model_house->where(array("parentid" => $id))->count();
    
        if ($this->model_house->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }
}